<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sign Up</title>
    <script src="./js/jquery.js"></script>
</head>

<body>
    <h3>注册</h3>
    <!-- <form action="http://127.0.0.1:8080" method="GET"> -->
    用户名：<input type="text" id="username"><br>
    密码：<input type="password" id="pwd"><br>
    确认密码：<input type="password" id="confirmPwd"><br>
    <input type="submit" id="submitBtn">
    <!-- </form> -->
    <script>
        $('#submitBtn').on('click', function () {
            var username = $('#username').val();
            var password = $('#pwd').val();
            var confirmPwd = $('#confirmPwd').val();
            // console.log(username, password, confirmPwd);
            // console.log((/\S+/g).test(username), username);
            if ((/\s*/g).test(username) && (/\S+/g).test(username) == false) {
                alert('请输入用户名');
            } else if ((/\s*/g).test(password) && (/\S+/g).test(password) == false) {
                alert('请输入密码');
            } else if ((/\s*/g).test(confirmPwd) && (/\S+/g).test(confirmPwd) == false) {
                alert('请输入确认密码');
            } else if (confirmPwd != password) {
                alert('两次密码不相同');
            } else {
                $.ajax({
                    url: 'http://127.0.0.1:8080',
                    method: 'get',
                    data: {
                        username: username,
                        password: password
                    },
                    success: function (data) {
                        data = JSON.parse(data);
                        console.log(data);
                        alert(data.prompt);
                        if (data.sign) {
                            location.href = './login.html';
                        }
                    }
                })
            }
        })

    </script>
</body>

</html>